#include <SDL_rotozoom.h>
#include "Object.h"
#include "Game.h"

 Object::Object(SDL_Surface *screen/*Kieu Du Lieu cua thu vien SDL*/)
{
	this->screen = screen;
	this->image = NULL;
	setPositions(0,0);
	setSpeed(0);
	setType(KindOfObject::kObject);
	lasttime = SDL_GetTicks();
}

 Object::Object(Game *game, const char *pathImage, double scaleRate)
{
	this->screen = game->screen ;
	this ->game = game;
	this ->scaleRate = scaleRate;
	loadImage(pathImage, scaleRate);
	setSpeed(0);
	setType(KindOfObject::kObject);
}

bool Object::checkColision(const MyRectangle &rect)
{
	return this->rect.collision(rect);
}
bool Object::checkColision(Object *obj)
{
	return checkColision(obj->rect) || (obj -> checkColision(this->rect));
}

void  Object::loadImage(const char * pathImage,double scaleRate)
{
	image = NULL;

	if (scaleRate == 1.0)
		image = IMG_Load(pathImage);// Ham Thu Vien 
	else
	{
		image = IMG_Load(pathImage);// Ham Thu Vien 
		image = zoomSurface(image, scaleRate,scaleRate, SMOOTHING_ON);// Ham Thu Vien 
	}
	rect.sdlRect.w = image ->w;
	rect.sdlRect.h = image ->h;
}
void  Object::draw()
{
	
	 SDL_BlitSurface( image, NULL, screen, &rect.sdlRect );// Ham Thu Vien 
	
	
}
void  Object::update()
{

}
void  Object::setRectangle(const MyRectangle &rect)
{
	this->rect = rect;
}
void Object::moveLeft()
{
	//if (rect.sdlRect.x - speed >= 0)
		setXPosition(rect.sdlRect.x - speed);
}
void Object::moveRight()
{
	//if (rect.sdlRect.x + rect.sdlRect.w + speed <= SCREEN_WIDTH)
		setXPosition(rect.sdlRect.x + speed);
}
void Object::moveDown()
{
	//if (rect.sdlRect.y + rect.sdlRect.h + speed <= SCREEN_)
		setYPosition(rect.sdlRect.y + speed);
}